'use strict'
let router=require('koa-router')();
let path=require('path');
let fs=require('fs');

let root=path.resolve('.');
let fullpath=path.join(root,'controllers');

let allfiles=fs.readdirSync(fullpath);

let resultfile=allfiles.filter((name)=>{
    return name.endsWith('.js') && name!=='index.js'; 
});

resultfile.map((x)=>{
    let tmppath=path.join(fullpath,x);
    let routes=require(tmppath);
    for(let i in routes){
        if(routes[i][0]==='get'){
            router.get(i,routes[i][1]);
        } else if(routes[i][0]==='post'){
            router.post(i,routes[i][1]);
        }   
    }
});

module.exports=()=>{
    return router.routes();
}